package com.leyou.aspect;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;


@Aspect
@Component
public class LogAspect {

    private static Logger logger = LoggerFactory.getLogger(LogAspect.class);

    @Before("execution(* com.leyou.controller.*.*(..))")
    public void beforeMethod(JoinPoint joinPoint) {
        StringBuilder sb = new StringBuilder();
        sb.append("------|");
        for (Object arg: joinPoint.getArgs()) {
            if (arg!=null){
                sb.append(arg.toString() + "|");
            }
        }
        sb.append("------");
        logger.info("before method---------------------");
        logger.info(sb.toString());
    }

    @After("execution(* com.leyou.controller.*.*(..))")
    public void afterMethod() {
        logger.info("after method---------------------");
    }

}
